import { Prisma } from '@prisma/client';
import { Transform } from 'class-transformer';
import { IsDefined, IsNotEmptyObject } from 'class-validator';
import { BaseDto, BaseFindDto, BaseQueryDto } from './base.dto';
import { WorkOrderTypeEnum } from '@/enums';

export class WorkOrderCreateDto extends BaseDto<Prisma.WorkOrderCreateInput> {}

export class WorkOrderUpdateDto extends BaseDto<Prisma.WorkOrderUpdateInput> {
  @IsDefined({ message: '条件必填' })
  @IsNotEmptyObject({ nullable: false }, { message: '条件参数必填' })
  where: Prisma.WorkOrderWhereUniqueInput;
}

export class WorkOrderRemoveDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;
}

export class WorkOrderFindDto extends BaseFindDto<
  Prisma.WorkOrderWhereUniqueInput,
  Prisma.WorkOrderSelect
> {}

export class WorkOrderQueryDto extends BaseQueryDto<
  Prisma.WorkOrderWhereUniqueInput & {
    realname?: string;
    mobile?: string;
  }
> {}

export class WorkOrderListDto extends BaseQueryDto<Prisma.WorkOrderWhereUniqueInput> {}

export class WorkOrderDto {
  @IsDefined({ message: '标题必填' })
  title: string;

  @IsDefined({ message: '内容必填' })
  info: string;

  @IsDefined({ message: '类型必填' })
  @Transform(({ value }) => Number(value))
  type: WorkOrderTypeEnum;

  images?: string[];
}

export class WorkOrderProcessDto {
  @IsDefined({ message: 'ID必填' })
  @Transform(({ value }) => Number(value))
  id: number;

  @IsDefined({ message: '处理结果必填' })
  reason: string;
}
